﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace WindowsStateService
{
    public class LogData
    {
        private EventLogEntryType logLevel;
        private DateTime dateTime;
        private string userName;
        private string content;
        private string source;
        private long event_id;
        private int index;
        private int log_type = 0; // system: 0  application :1

        public EventLogEntryType LogLevel 
        { 
            get { return logLevel; }
            set { logLevel = value; } 
        }

        public DateTime DateTime
        {
            get { return dateTime; } set { dateTime = value; }
        }

        public string UserName
        {
            get { return userName; }
            set { userName = value; }
        }

        public string Content 
        { 
            get { return content; }
            set { content = value; }
        }
        public string Source
        {
            get { return source; }
            set {  source = value; }
        }

        public long EventId
        {
            get { return event_id; }
            set { event_id = value; }
        }

        public int Index
        {
            get { return index; }
            set { index = value; }
        }

        public int LogType
        {
            get { return log_type; }
            set { log_type = value; }
        }

        public LogData() { }

        public override string ToString()
        {
            return $"{index} {GetLogLevel(logLevel)} {dateTime.ToString("yyyy-MM-dd HH:mm:ss")} {content} {source} {event_id}";
        }

        private string GetLogLevel(EventLogEntryType level)
        {
            string result = string.Empty;
            switch (level)
            {
                case EventLogEntryType.Error:
                    result = "ERROR";
                    break;
                case EventLogEntryType.Warning:
                    result = "Warning";
                    break;
                case EventLogEntryType.Information:
                    result = "Information";
                    break;
                case EventLogEntryType.FailureAudit:
                    result = "FailureAudit";
                    break;
                case EventLogEntryType.SuccessAudit:
                    result = "SuccessAudit";
                    break;
            }
            return result;
        }
    }
}
